﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SuaThongTinND : System.Web.UI.Page
{
    private User oUser;
    protected void Page_Load(object sender, EventArgs e)
    {
        oUser =(User) Session["user"];
        if (oUser == null) Response.Redirect("/");
        if (!IsPostBack)
        {
            GetInfo(oUser);
        }
    }

    private void GetInfo(User user)
    {
        txtAddress.Text = user.address;
        txtFullname.Text = user.fullname;
        txtPhone.Text = user.mobile;
        txtemail.Text = user.Email;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dulieuDataContext db = new dulieuDataContext();
        var oUserUpdate = db.Users.FirstOrDefault(a => a.UserName == oUser.UserName);
        if (oUserUpdate != null)
        {
            oUserUpdate.address = txtAddress.Text;
            oUserUpdate.fullname = txtFullname.Text;
            oUserUpdate.mobile = txtPhone.Text;
            oUserUpdate.Email = txtemail.Text;
            db.SubmitChanges();
            Session["user"] = oUserUpdate;
            MessageBox.Show("Cập nhật thông tin thành công");
        }
    }
}